home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / convert / c_conver / itou.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-11-19  |  768 b   |  30 lines

  1. /*----- ARCHIVE itou.c -----------------------------------------------------*/
  2. /*
  3. **    itou -- convert nbr to unsigned decimal string of width sz
  4. **        right adjustsed, blank filled; returns str
  5. **
  6. **        if sz > 0 terminate with null byte
  7. **        if sz = 0 find end of string
  8. **        if sz < 0 use last byte for data
  9. */
  10. #define NULL    0
  11. itou(nbr,str,sz) int nbr; char str[]; int sz; {
  12.     int lowbit;
  13.     if (sz>0) str[--sz]=NULL;
  14.     else if (sz<0) sz=-sz;
  15.     else while (str[sz]!=NULL) ++sz;
  16.     while (sz) {
  17.         lowbit=nbr&1;
  18.         nbr=(nbr>>1)&32767;    /* divide by 2 */
  19.         str[--sz]=((nbr%5)<<1)+lowbit+'0';
  20.         if ((nbr=nbr/5)==0) break;
  21.     }
  22.     while (sz) str[--sz]=' ';
  23.     return str;
  24. }
  25. to directory buffer
  26.     ;
  27. DIRBUF:    DS    ENTRIES*16    ;directory buffer
  28.     ;
  29.     END    BEGIN
  30. PA:X